/*
 * This file is part of LazyCipher. LazyCipher is free software: you can
 * redistribute it and/or modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version. LazyCipher is distributed in
 * the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
 * the GNU General Public License for more details. You should have received a
 * copy of the GNU General Public License along with LazyCipher. If not, see
 * <http://www.gnu.org/licenses/>.
 */
package org.lazycoder.Crypto.Keys;

import org.lazycoder.Crypto.Letter;
import org.lazycoder.Crypto.Message;

/**
 * @author Matthew Bayliss
 */
public class TextKey implements Key {
	String	key		= "";
	Message	mKey;
	Integer	index	= 0;

	public TextKey(String k) {
		key = k;
		mKey = new Message(k);
	}

	@Override
	public Integer getInteger() {
		try {
			return Integer.parseInt(key);
		} catch (NumberFormatException e) {
			return 0;
		}
	}

	@Override
	public String getString() {
		return key;
	}

	@Override
	public Letter getLetter() {
		return mKey.getLetter(index);
	}

	@Override
	public void next() {
		index++;
		if (!getLetter().isAlphabetic()) {
			next();
		}
	}

}
